package com.zjljr.oshiapp.service;

import org.springframework.stereotype.Service;
import oshi.SystemInfo;
import oshi.hardware.CentralProcessor;
import oshi.hardware.HardwareAbstractionLayer;

import java.text.DecimalFormat;

@Service
public class CpuLoadMetricsService {


    public double[] getCpuLoad() {
        SystemInfo si = new SystemInfo();
        HardwareAbstractionLayer hardware = si.getHardware();
        CentralProcessor processor = hardware.getProcessor();
        // 统计1秒内所有核的使用率
        double[] cpuLoad = processor.getProcessorCpuLoad(1000);
        return cpuLoad;
    }

}
